<template>
  <div class="inner">
    <div v-if="right">
      <div class="title">
        <p>活动公告</p>
      </div>
      <div class="center">
        <div class="main_content" @click="look(newxx[0].id)">
          <div>
            <img
              style="width:335px;height:209px"
              v-if="newxx[0].thumb"
              :src="IP+newxx[0].thumb"
              alt
            />
          </div>
          <div class="zs_k">
            <p class="zs_title">{{newxx[0].title}}</p>
            <span
              v-if="newxx[0].description"
              class="zs_content"
            >{{newxx[0].description.length>50?newxx[0].description.substr(0,50)+'...':newxx[0].description}}</span>
            <p class="more">查看更多</p>
          </div>
        </div>
        <div class="second_content">
          <ul>
            <li @click="look(item.id)" v-for="(item,index) of  currentPageData" :key="index">
              <p>{{item.title}}</p>
              <span>{{item.inputtime.slice(0,10)}}</span>
            </li>
          </ul>
        </div>
      </div>
      <div id="page">
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :pager-count="5"
          :page-size="pageSize"
          layout="  prev, pager, next"
          :total="this.productList.length"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      // message: [{}],
      right: true,
      newxx: [{}],
      productList: [{}], //所有数据
      totalPage: 1, // 统共页数，默认为1
      currentPage: 1, //当前页数 ，默认为1
      pageSize: 10, // 每页显示数量
      currentPageData: [], //当前页显示内容
    };
  },
  props: ["id"],

  mounted() {
    this.setCurrentPageData();
    this.new();
  },
  methods: {
    look(id) {
      this.$router
        .push({
          path: `/guanwugongkai/huodonggonggaodetail?id=${id}`,
          query: { orderId: 2, bool: true },
        })
        .catch((err) => {
          err;
        });
    },
    new() {
      this.$api
        .get(`${this.tableList}huodonggonggao-1-10000000`)
        .then((res) => {
          // console.log(res);
          this.newxx = res.data.page.list;
        });
    },
    // 设置当前页面数据，对数组操作的截取规则为[0~10],[10~20]...,
    setCurrentPageData() {
      this.$api
        .get(`${this.tableList}huodonggonggao-1-10000000`)
        .then((res) => {
          // 计算一共有几页
          this.totalPage = Math.ceil(this.productList.length / this.pageSize);

          // 计算得0时设置为1
          this.totalPage = this.totalPage == 0 ? 1 : this.totalPage;
          this.productList = res.data.page.list;
          this.productList.splice(0, 1);
          let begin = (this.currentPage - 1) * this.pageSize;
          let end = this.currentPage * this.pageSize;
          //当前页的数据等于
          this.currentPageData = this.productList.slice(begin, end);
        });
    },
    handleCurrentChange(val) {
      if (val != this.currentPage) {
        this.currentPage = val;
      }

      // this.page = val;
      this.setCurrentPageData(`${this.tableList}huodonggonggao-1-1000000`);
    },
  },

  watch: {},
};
</script>
<style scoped>
.gwgk.content {
  display: flex;
  justify-content: space-between;
  color: #4e4b4b;
  max-width: 1200px;
  font-size: 24px;
  margin: auto;
  line-height: 40px;
  padding-top: 90px;
  box-sizing: border-box;
}
.title > p {
  padding-left: 35px;
  margin-bottom: 10px;
}
.gwgk .title {
  font-size: 30px;
  border-bottom: 2px solid rgb(107, 128, 173);
  color: rgb(107, 128, 173);
}
.gwgk li {
  list-style: none;
}
.gwgk ul,
li,
p {
  padding: 0px;
  margin: 0px;
}

.gwgk .right {
  background: rgb(230, 230, 230);
  width: 980px;
  height: 1190px;
  padding: 0 30px 0;
  box-sizing: border-box;
}

.gwgk .blue {
  color: rgb(25, 67, 119);
}
.zs_k {
  width: 50%;
  display: flex;
  flex-direction: column;

  margin-left: 68px;
}
.zs_title {
  font-weight: bold;
  font-size: 16px;
  color: #333333;
  margin-bottom: 25px;
}
.zs_content {
  font-size: 14px;
  color: #666666;
  line-height: 30px;
  margin-bottom: 20px;
}
.right .inner .more {
  color: white;
  background: #4e69a1;
  width: 195px;
  height: 40px;
  border-radius: 5px;
  text-align: center;
  font-size: 16px;
  line-height: 40px;
}
.more,
.zs_content,
.zs_title,
.main_content img {
  cursor: pointer;
}

.right .inner {
  padding-top: 5px;
  padding-bottom: 80px;
}
.right .inner .main_content {
  display: flex;
  padding: 30px 35px 20px;
}
.second_content {
  height: 592px;
}
.right .inner .second_content li {
  display: flex;
  padding: 25px 35px 15px;
  width: 900px;
  font-size: 16px;
  box-sizing: border-box;
  justify-content: space-between;
  border-top: 1px solid rgb(216, 216, 216);
  color: black;
  cursor: pointer;
}
.right .inner .second_content li:last-child {
  border-bottom: 1px solid rgb(216, 216, 216);
}
.bread {
  max-width: 1150px;
  margin: auto;
  height: 60px;
}
/*馆务公开 新闻咨询 */
.gwgk span {
  display: block;
}
.title_top {
  text-align: center;
}
.xwzx_title {
  color: #060606;
  font-size: 24px;
  margin-top: 20px;
}
.xwzx_second_title {
  font-size: 16px;
  color: #3e3e3e;
  margin-bottom: 10px;
}

.ziti {
  font-size: 16px;
  color: #666666;
}
/* fenye */
#page {
  text-align: center;
  margin-top: 65px;
}
#page >>> .el-pager li {
  border: 1px solid gray;
  margin-right: 20px;
  min-width: 25px;
  height: 25px;
  border-radius: 2px;
}
#page >>> .el-pager li.active {
  color: white;
  cursor: default;
  background: rgb(78, 105, 161);
}
#page >>> .el-icon-arrow-right::before,
#page >>> .el-icon-arrow-left::before {
  content: "";
}
#page >>> .el-pagination .btn-next,
#page >>> .el-pagination .btn-prev {
  height: 40px;
  background: url("../../assets/image/fenye_right.png") no-repeat;
  background-size: auto 30px;
}

#page >>> .el-pagination .btn-prev {
  background: url("../../assets/image/fenye_left.png") no-repeat;
  background-size: auto 30px;
}
</style>